﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"

#include "IStructureSlopeLine.h"
#include "NdbObjectSchematic.h"
#include "DbDataSchema.h"
#include "ICurve2d.h"
#include "Matrix4d.h"
#include "ElementCreationOptions.h"
#include "IElementDeletionComponent.h"
#include "StructureSlopeDefinitionType.h"
#include "ElementId.h"

namespace gcmp 
{
    class IElement;
    class ILine3d;
    class IGraphicsLine;
    class IInstance;
    // 结构楼板坡度线
    class GM_STRUCTURE_EXPORT StructureSlopeLine : public NdbObjectSchematic, public IStructureSlopeLine
    {
        CANNOT_COPY_OR_ASSIGN(StructureSlopeLine)
    private:
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, StructureSlopeLine, gcmp::NdbObjectSchematic, F087BE25 - E3A5 - 4488 - 8646 - 913CFE777747, gmstructure, IStructureSlopeLine)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(StructureSlopeDefinitionType, SlopeDefinitionType)
            DATA(double, StartElevationOffset)
            DATA(double, EndElevationOffset)
            DATA(ElementId, InstanceId)
        DBOBJECT_DATA_END
    public:
        virtual ~StructureSlopeLine() {}
        static StructureSlopeLine* Create(
            IDocument* pDoc,
            const Vector3d& startPt,
            const Vector3d& endPt,
            ElementCreationOptions eco = ElementCreationOptions::Normal
        );

#pragma region IStructureSlopeLine接口
    public:
        // 起点偏移值
        virtual double GetStartElevationOffset() const override{ return this->GetStartElevationOffset__(); }
        virtual bool SetStartElevationOffset(double offset) override { this->SetStartElevationOffset__(offset); return true; }

        // 终点偏移值
        virtual double GetEndElevationOffset() const override { return this->GetEndElevationOffset__(); }
        virtual bool SetEndElevationOffset(double offset) override { this->SetEndElevationOffset__(offset); return true; }

        // 坡度线关联的InstanceId
        virtual ElementId GetInstanceId() const override{ return this->GetInstanceId__(); }
        virtual bool SetInstanceId(ElementId instanceId) override{ this->SetInstanceId__(instanceId); return true; }

        // 坡度起点
        virtual Vector3d GetStart() const override;

        // 坡度终点
        virtual Vector3d GetEnd() const override;

        // 获取坡度角（弧度）
        virtual double GetSlopeAngle() const override;

        // 坡度线的三维倾斜线
        virtual OwnerPtr<ILine3d> GetSlopeLine() const override;

        // 坡度线的额图形显示直线和箭头
        virtual OwnerPtr<IGraphicsElementShape> GetGraphicsLineAndArrow() const override;

#pragma endregion IStructureSlopeLine接口

#pragma region 其他
    public:
        // 坡度定义方式
        StructureSlopeDefinitionType GetSlopeDefinitionType() const { return this->GetSlopeDefinitionType__(); }
        bool SetSlopeDefinitionType(StructureSlopeDefinitionType type) { this->SetSlopeDefinitionType__(type); return true; }

        // 坡度线的图形显示直线
        OwnerPtr<IGraphicsLine> GetGraphicsLine() const;

        ElementId GetOwnerElementId() const;
    private:
        IDocument* GetDocument() const;
#pragma endregion 其他

#pragma region IExternalObject接口
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }

        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;

        virtual void ReportParents(IElementParentReporter& reporter) const override;

        virtual bool FinishEditing() override;
#pragma endregion IExternalObject接口

#pragma region NdbObject接口
    public:
        virtual NdbObject* GetTopOwnerObject() const override;
#pragma endregion NdbObject接口

    public:
        static gcmp::UniIdentity GetImplementationUid();
    };

}// namespace gcmp
